
export class EventHubService{

    /**
     * 通知监听
     * @param {string} key 事件键
     * @param {string} origin 监听者来源
     * @param {Function} handle 事件处理函数
     */
    static on(key:string,origin:string,handle:Function){
        let eventhub = window["EventHubs"] = window["EventHubs"] || {};
        let hub = eventhub[key] = eventhub[key] || {};
        hub[origin] = handle;
    }

    /**
     * 触发事件
     * @param {string} key //事件键
     * @param options 需要传递的值
     */
    static emit(key:string,options:any = {}){
        let eventhub = window["EventHubs"] = window["EventHubs"] || {};
        let handles = eventhub[key];
        if(handles){
            for(let k in handles){
                if(handles.hasOwnProperty(k)){
                    options.origin = k;
                    handles[k](options);
                }
            }
        }
    }


}
